<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="referrer" content="no-referrer" />
    <title>压平分析</title>
    <style>
        body {
            position: absolute;
            margin: 0;
            width: 100%;
            height: 100%;
        }

        #mapContainer {
            left: 0px;
            top: 0px;
            width: 100%;
            height: 100%;
            float: left;
        }
    </style>
</head>

<body>
    <div id="mapContainer" style="position: relative;"></div>
</body>
<script src='/GiswayEngine.js'></script>
<script type="text/javascript">
    window.app = new GE.App('mapContainer', {
        position: [120.14722331340128, 30.27129365792725, 1000], //相机的位置
        lookAt: [120.14722331340128, 30.27129365792725, 0], //相机看向的地图位置
        cameraScrollSpeed: 5, //鼠标滚动时，控制相机移动的速度
        minZoom: 3, //允许地图的最小层级
        maxZoom: 18, //允许地图的最大层级
        ambientLightIntensity: 5,
        useDefaultTexture: true, //是否使用瓦片默认纹理
        isOpenClapProject: true, //开启压平分析
        polygonPointNumInShader: 25, //多边形的最大顶点数量, 该属性只在压平分析，淹没分析，压平分析中使用，如果不使用这三个分析功能不要设置该属性，否则会对性能有影响
        background: "Fog", //背景的类型，参数有如下类型：None, Fog, Color, Gradient, Image, Sky, Image。使用Fog地图的性能会比较好
        // backGroundColorA:'#AAAAFF', //当background的值为Gradient时，需要配置该参数。最下端颜色，默认值为#0000FF
        // backGroundColorB:'#0000FF', //当background的值为Gradient时，需要配置该参数。最上端颜色，默认值为#FF0000
        // backGroundColor: '#F5F5F5', //当background的值为Color时，需要配置该参数，默认值为#00BFFF
        // imageUrl: 'http://localhost:9000/examples/assets/img_logo.39362dc1.png', //当background的值为Image时，需要配置该参数。默认值为null
        baseLayer: [
            //影像底图
            {
                url: ' https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', //影像底图的url
                // url: 'http://115.236.87.26:8848/googleTiles/china_image/{z}/{y}/{x}.jpg',
                urlDecimal: true, //影像底图url中的瓦片行列号是否是十进制，true表示十进制，false表示十六进制
                tileType: 'image', //影像底图
                canNotSelect: false, //true表示该图层不参与射线拾取，false表示图层参与射线拾取
            },
            //shape底图
            {
                // url: 'http://192.168.2.100:8702/resources/1b8b2fcb26b020120aebfac57779e06a/ShpCLipper/L{z}/{y}/{x}.shp', //shape底图的url
                url: 'http://localhost:9009/examples/resources/shape/Tiles/L{z}/{y}/{x}.shp', //shape底图的url
                urlDecimal: true, //shape底图url中的瓦片行列号是否是十进制，true表示十进制，false表示十六进制
                tileType: 'shape',  //shape底图
                canNotSelect: true, //true表示该图层不参与射线拾取，false表示图层参与射线拾取
                merge: true //几何体是否合并
            }
        ]
    });

    window.app.on('Click', function (e) {
        console.log(e);
    });

    var clapAnalysis;
    btn();

    function btn() {
        let button1 = new GE.Button('打开压平分析', function () {
            openClapArea();
        });
        app.ui.add(button1);

        let button2 = new GE.Button('关闭压平分析', function () {
            closeClapArea();
        });
        app.ui.add(button2);
    }

    function openClapArea() {
        if (!clapAnalysis) {
            let pointArray = [ //3857表示web墨卡托坐标系，4326表示经纬度坐标
                // new GE.Point(13376713.90129997, 3540579.2959903134, 0, '3857'),
                // new GE.Point(13376711.98134067, 3539826.5375406537, 0, '3857'),
                // new GE.Point(13377952.49603797, 3539759.3270052206, 0, '3857'),
                // new GE.Point(13378008.185227688, 3540675.3111583497, 0, '3857')

                new GE.Point(13374727.717611784, 3538469.996754151, 0, '3857'),
                new GE.Point(13374727.717611784 - 500, 3538469.996754151, 0, '3857'),
                new GE.Point(13374727.717611784 - 500, 3538469.996754151 + 500, 0, '3857'),
                new GE.Point(13374727.717611784, 3538469.996754151 + 500, 0, '3857')
            ];
            let clapData = {
                pointArray: pointArray,  //多边形的顶点数组
                zoomRange: { minZoom: 16, maxZoom: 18 }
            };
            clapAnalysis = new GE.ClapAnalysis(clapData);
        }
        let isOpen = clapAnalysis.openAnalysis();
        if (!isOpen) {
            alert('请确保压平区域在已加载数据范围内。');
        }
    }

    function closeClapArea() {
        if (!clapAnalysis) {
            return;
        }
        clapAnalysis.closeAnalysis();
    }

    loadModel('http://localhost:9000/examples/resources/fbx/xqazm.fbx', 'fbx');
    function loadModel(url, type, extraUrl) {
        model = new GE.OverLay({
            type: type,
            url: url,
            // dracoPluginUrl: 'http://localhost:9000/examples/resources/plugin/draco/',
            mtlUrl: extraUrl,
            // url: 'http://localhost:9000/examples/resources/fbx/ceshi1.FBX',
            // url:'http://192.168.2.43:9000/examples/resources/fbx/box.gltf',
            position: [120.14722331340128, 30.27129365792725, 1.0],
            changeEmissive: true,
            // gltfUpAxis: 'Z',
            gltfUpAxis: 'Y',
            scale: [1, 1, 1],
            canNotSelect: true,
            // rotation: [90, 0, 0],
            success: null,
        })
        app.add(model);
        // window.app.camera.addIntersectObjWithEye(model); //该模型和相机做相交检测，避免穿透

        window.model = model;
    }


</script>

</html>